package goliath;

import pulpcore.animation.event.SceneChangeEvent;
import pulpcore.animation.Color;
import pulpcore.image.CoreFont;
import pulpcore.image.CoreImage;
import pulpcore.image.Colors;
import static pulpcore.image.Colors.WHITE;
import pulpcore.scene.Scene2D;
import pulpcore.sprite.*;
import goliath.BasicDemo;

public class TitleScene extends Scene2D {
    
    Button playButton;
    Button editButton;
    Button optionsButton;
    Group componentLayer;
    Slider levelSelect;
    
    @Override
    public void load() {
        add(new FilledSprite(Colors.DARKGRAY));

        CoreFont font = CoreFont.getSystemFont().tint(WHITE);

        Label title = new Label(CoreFont.load("hello.font.png"), "Tower Construction Kit", 320, 240, 600,100);
        title.setAnchor(Sprite.CENTER);
        playButton = Button.createLabeledButton("Play Stage", 320, 320);
        playButton.setAnchor(Sprite.CENTER);

        editButton = Button.createLabeledButton("Edit Stage", 320, 320+playButton.height.getAsInt());
        editButton.setAnchor(Sprite.CENTER);

        levelSelect = new Slider("slider.png", "slider-thumb.png", 100, 80);
        levelSelect.setAnchor(Sprite.WEST);
        levelSelect.setRange(1,3);
        Label label3 = new Label(font, "Level: %d ", 100, 100);
        label3.setFormatArg(levelSelect.value);
        label3.setAnchor(Sprite.EAST);



        componentLayer = new Group();
        componentLayer.add(playButton);
        componentLayer.add(editButton);
        componentLayer.add(optionsButton);

        componentLayer.add(levelSelect);
        componentLayer.add(label3);

//        add(new ImageSprite("background.png", 0, 0));
        add(title);
        addLayer(componentLayer);
    }
    
    @Override 
    public void update(int elapsedTime) {
        if (playButton.isClicked()) {
            // Animated alternative to Stage.setScene(new HelloWorld());
            componentLayer.alpha.animateTo(0, 300);
            addEvent(new SceneChangeEvent(new BasicDemo(levelSelect.value.getAsInt(),false), 300));
        }
        if (editButton.isClicked()) {
            // Animated alternative to Stage.setScene(new HelloWorld());
            componentLayer.alpha.animateTo(0, 300);
            addEvent(new SceneChangeEvent(new BasicDemo(levelSelect.value.getAsInt(),true), 300));
        }
    }
}
